package com.example.xadmin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xadmin.common.Pageable;
import com.example.xadmin.common.Result;
import com.example.xadmin.dao.SysUserMapper;
import com.example.xadmin.pojo.SysUser;
import com.example.xadmin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private SysUserService userDao;

    @ResponseBody
    @RequestMapping("/list")
    public Object list(Pageable pageable){
        Page res = userDao.page(pageable.toPage());
        return Result.ok((int)res.getTotal(),res.getRecords()) ;
    }


    @RequestMapping("/add")
    public String list(Model model){
        model.addAttribute("sysUser",new SysUser());
        return "user/user-add";
    }

}
